/*     */ package com.qmsk.business.store.transferbill.controller;
/*     */ 
/*     */ import com.qmsk.business.store.instockbill.service.InStockBillService;
/*     */ import com.qmsk.business.store.outstockbill.service.OutStockBillService;
/*     */ import com.qmsk.business.store.transferbill.dao.TransferBillDAO;
/*     */ import com.qmsk.business.store.transferbilldtl.dao.TransferDtlDAO;
/*     */ import com.qmsk.business.store.warehouse.dao.WarehouseDao;
/*     */ import com.qmsk.session.UserSessionInfo;
/*     */ import com.utils.basic.MapUtils;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadManyRows;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.sql.SQLException;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"transferBill"})
/*     */ public class TransferBillController
/*     */ {
/*  40 */   private static final Logger logger = Logger.getLogger(TransferBillController.class);
/*     */ 
/*     */   @Autowired
/*     */   private TransferBillDAO dao;
/*     */ 
/*     */   @Autowired
/*     */   private TransferDtlDAO dtlDao;
/*     */ 
/*     */   @Autowired
/*     */   private OutStockBillService outStockBillService;
/*     */ 
/*     */   @Autowired
/*     */   private InStockBillService inStockBillService;
/*     */ 
/*     */   @Autowired
/*     */   private WarehouseDao warehouseDao;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/opt/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOptShopId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize) { nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/*  60 */       Map params = new HashMap();
/*  61 */       MapUtils.addToMap(params, "id", 
/*  62 */         RequestUtils.getString(request, "id"));
/*  63 */       MapUtils.addToMap(params, "tbNo", 
/*  64 */         RequestUtils.getString(request, "tbNo"));
/*  65 */       MapUtils.addToMap(params, "fShopId", 
/*  66 */         RequestUtils.getString(request, "fShopId"));
/*  67 */       MapUtils.addToMap(params, "tShopId", 
/*  68 */         RequestUtils.getString(request, "tShopId"));
/*  69 */       MapUtils.addToMap(params, "status", 
/*  70 */         RequestUtils.getInt(request, "status"));
/*  71 */       MapUtils.addPercentToMap(params, "maker", 
/*  72 */         RequestUtils.getString(request, "maker"));
/*  73 */       MapUtils.addToMap(params, "groupId", 
/*  74 */         RequestUtils.getInt(request, "groupId"));
/*  75 */       MapUtils.addToMap(params, "dtCreateStart", 
/*  76 */         RequestUtils.getDate(request, "dtCreateStart"));
/*  77 */       MapUtils.addToMap(params, "dtCreateEnd", 
/*  78 */         RequestUtils.getDate(request, "dtCreateEnd"));
/*  79 */       MapUtils.addToMap(params, "dtTrsfStart", 
/*  80 */         RequestUtils.getDate(request, "dtTrsfStart"));
/*  81 */       MapUtils.addToMap(params, "dtTrsfEnd", 
/*  82 */         RequestUtils.getDate(request, "dtTrsfEnd"));
/*  83 */       GsonEbRst gsonEbRst = this.dao.getGsonOfAll(params, nPageIdx, nPageSize);
/*  84 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/*  86 */       logger.error(e);
/*  87 */       ResponseUtils.setErrorMsgResponse(
/*  88 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/dtlId/{id}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListDtlId(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Long id)
/*     */   {
/*     */     try {
/*  96 */       GsonEbRst gsonEbRst = this.dtlDao.getGsonOfId(id);
/*  97 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/*  99 */       logger.error(e);
/* 100 */       ResponseUtils.setErrorMsgResponse(
/* 101 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/id/{id}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListId(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Long id)
/*     */   {
/*     */     try {
/* 109 */       GsonEbRst gsonEbRst = this.dao.getGsonOfId(id);
/* 110 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/* 112 */       logger.error(e);
/* 113 */       ResponseUtils.setErrorMsgResponse(
/* 114 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/*     */     try
/*     */     {
/* 132 */       int nResult = 0;
/* 133 */       Long id = null;
/* 134 */       String tbNo = null;
/* 135 */       String sData = RequestUtils.getStringOfData(request);
/* 136 */       String sDtl = RequestUtils.getString(request, "transferDtl");
/* 137 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 138 */       ParserDataSetJson p_dtl = ParserDataSetJson.fromString(sDtl);
/*     */       Iterator localIterator;
/*     */       GsonHeadOneRow r;
/* 140 */       if ((p != null) && (p.isExistsInsertRows())) {
/* 141 */         tbNo = this.dao.getMaxBillNo(shopId);
/* 142 */         for (localIterator = p.getListInsertRows().iterator(); localIterator.hasNext(); ) { r = (GsonHeadOneRow)localIterator.next();
/* 143 */           r.autoAddHeadData("tbNo", tbNo);
/*     */         }
/* 145 */         nResult = this.dao.applyUpdates(p, "id");
/* 146 */         if (nResult > 0) {
/* 147 */           id = (Long)((GsonHeadOneRow)p.getListInsertRows().get(0))
/* 148 */             .getValueOfName("id");
/*     */         }
/*     */       }
/*     */ 
/* 152 */       if (id != null) {
/* 153 */         for (localIterator = p_dtl.getListInsertRows().iterator(); localIterator.hasNext(); ) { r = (GsonHeadOneRow)localIterator.next();
/* 154 */           r.autoAddHeadData("id", id);
/*     */         }
/* 156 */         nResult = this.dtlDao.applyUpdates(p_dtl);
/*     */       }
/* 158 */       if (nResult > 0) {
/* 159 */         DbConnection.commit();
/* 160 */         if (id != null) {
/* 161 */           String[] heads = { "id", "tbNo" };
/* 162 */           Object[] datas = { id, tbNo };
/* 163 */           ResponseUtils.toGsonEbRst(heads, datas, response);
/* 164 */           return; }
/* 165 */         ResponseUtils.setSqlResultResponse(nResult, 
/* 166 */           RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 167 */           response);
/*     */ 
/* 169 */         return; }
/* 170 */       DbConnection.rollback();
/* 171 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 172 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 173 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 176 */       logger.error(e);
/* 177 */       DbConnection.rollback();
/* 178 */       ResponseUtils.setErrorMsgResponse(
/* 179 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 180 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void edit(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/*     */     try
/*     */     {
/* 198 */       int nResult = 0;
/* 199 */       String sData = RequestUtils.getStringOfData(request);
/* 200 */       String sDtl = RequestUtils.getString(request, "transferDtl");
/* 201 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 202 */       ParserDataSetJson p_dtl = ParserDataSetJson.fromString(sDtl);
/*     */ 
/* 204 */       if ((p != null) && (p.isExistsUpdateRows())) {
/* 205 */         nResult = this.dao.applyUpdates(p);
/*     */       }
/* 207 */       if (p_dtl != null) {
/* 208 */         nResult += this.dtlDao.applyUpdates(p_dtl);
/*     */       }
/*     */ 
/* 211 */       if (nResult > 0)
/* 212 */         DbConnection.commit();
/*     */       else {
/* 214 */         DbConnection.rollback();
/*     */       }
/* 216 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 217 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 218 */         response);
/*     */     } catch (Exception e) {
/* 220 */       logger.error(e);
/* 221 */       DbConnection.rollback();
/* 222 */       ResponseUtils.setErrorMsgResponse(
/* 223 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 224 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 240 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 242 */       String[] strParams = id.split(",");
/* 243 */       int nResult = 0;
/*     */ 
/* 245 */       nResult = this.dtlDao.deleteByInId(strParams);
/*     */ 
/* 247 */       if (nResult > 0) {
/* 248 */         nResult = this.dao.deleteParams(strParams);
/*     */       }
/* 250 */       if (nResult > 0)
/* 251 */         DbConnection.commit();
/*     */       else {
/* 253 */         DbConnection.rollback();
/*     */       }
/* 255 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 256 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 257 */         response);
/*     */     } catch (Exception e) {
/* 259 */       DbConnection.rollback();
/* 260 */       logger.error(e);
/* 261 */       ResponseUtils.setErrorMsgResponse(
/* 262 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 263 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"check/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void check(HttpServletRequest request, HttpServletResponse response) throws SQLException
/*     */   {
/* 271 */     int nResult = 0;
/* 272 */     Long id = RequestUtils.getLong(request, "id");
/* 273 */     Long userId = UserSessionInfo.getIntUserIdOfRequest(request);
/*     */     try {
/* 275 */       nResult = this.dao.updateStatusOfId(id).intValue();
/* 276 */       if (nResult > 0) {
/* 277 */         GsonHeadOneRow g = this.dao.getOneRowOfId(id);
/* 278 */         String billNo = (String)g.getValueOfName("tbNo");
/* 279 */         Long fShopId = ObjectComm.objectToLong(g
/* 280 */           .getValueOfName("fShopId"));
/* 281 */         Long tShopId = ObjectComm.objectToLong(g
/* 282 */           .getValueOfName("tShopId"));
/* 283 */         GsonHeadManyRows m = this.dtlDao.getManyRowsDtlOfId(id);
/* 284 */         if ((m != null) && (m.isExistsData())) {
/* 285 */           String outNo = this.outStockBillService.getOutNo(fShopId);
/* 286 */           String[] outHead = { "shopId", "outTpId", 
/* 287 */             "outNo", "linkNo", "maker", "makeDate", "status", 
/* 288 */             "outDate" };
/* 289 */           Object[] outData = { fShopId, Integer.valueOf(4), outNo, 
/* 290 */             billNo, userId, new Date(), Integer.valueOf(0), new Date() };
/* 291 */           nResult = this.outStockBillService.insertOutBill(
/* 292 */             new GsonHeadOneRow(outHead, outData), m).intValue();
/*     */ 
/* 293 */           if (nResult > 0) {
/* 294 */             nResult = this.outStockBillService.check(
/* 295 */               this.outStockBillService.getLastId(), response).intValue();
/*     */           }
/*     */ 
/* 297 */           if (nResult > 0) {
/* 298 */             String inNo = this.inStockBillService.getInNo(tShopId);
/* 299 */             Long tHouseId = this.warehouseDao
/* 300 */               .getHouseIdOfShopId(tShopId);
/* 301 */             if ((tHouseId != null) && (tHouseId.longValue() > 0L)) {
/* 302 */               m.autoAddHeadData("houseId", tHouseId);
/* 303 */               m.setHeadValueOfObject("houseId", tHouseId);
/* 304 */               String[] inHead = { "shopId", "inTpId", 
/* 305 */                 "inNo", "linkNo", "maker", "makeDate", 
/* 306 */                 "status", "inDate" };
/* 307 */               Object[] inData = { tShopId, Integer.valueOf(3), inNo, 
/* 308 */                 billNo, userId, new Date(), Integer.valueOf(0), new Date() };
/* 309 */               nResult = this.inStockBillService.insertOutBill(
/* 310 */                 new GsonHeadOneRow(inHead, inData), m).intValue();
/*     */             }
/*     */             else {
/* 312 */               DbConnection.rollback();
/* 313 */               ResponseUtils.setErrorMsgResponse("未找到入货库房", response);
/* 314 */               return;
/*     */             }
/*     */           }
/*     */ 
/* 318 */           if (nResult > 0) {
/* 319 */             nResult = this.inStockBillService.check(
/* 320 */               this.inStockBillService.getLastId(), response).intValue();
/*     */           }
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/* 325 */       if (nResult > 0)
/* 326 */         DbConnection.commit();
/*     */       else {
/* 328 */         DbConnection.rollback();
/*     */       }
/* 330 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 331 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 332 */         response);
/*     */     } catch (Exception e) {
/* 334 */       DbConnection.rollback();
/* 335 */       logger.error(e);
/* 336 */       ResponseUtils.setErrorMsgResponse(
/* 337 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 338 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.store.transferbill.controller.TransferBillController
 * JD-Core Version:    0.5.3
 */